namespace Beetle;

public class ServerImpl<T> : ServerBase<T> where T : Package
{
	private IServerHandler a;

	protected override void OnOpening()
	{
		base.OnOpening();
		a.Opened(this);
	}

	public ServerImpl(string name, IServerHandler handler)
	{
		base.Name = name;
		a = handler;
	}

	protected override void OnServerError(object sender, TcpServerErrorArgs e)
	{
		base.OnServerError(sender, e);
		a.ServerError(this, e);
	}

	protected override void OnCreatingChannel(object sender, ChannelCreatingArgs e)
	{
		base.OnCreatingChannel(sender, e);
		a.SocketConnect(this, e);
	}

	protected override void OnMessageReceive(PacketRecieveMessagerArgs e)
	{
		base.OnMessageReceive(e);
		a.ChannelReceiveMessage(this, e);
	}

	protected override void OnDisposed(object sender, ChannelDisposedEventArgs e)
	{
		base.OnDisposed(sender, e);
		a.ChannelDisconnect(this, e);
	}

	protected override void OnConnected(object sender, ChannelEventArgs e)
	{
		base.OnConnected(sender, e);
		a.ChannelCreated(this, e);
	}

	protected override void OnServerDisposed()
	{
		base.OnServerDisposed();
		a.Disposed(this);
	}

	protected override void OnError(object sender, ChannelErrorEventArgs e)
	{
		base.OnError(sender, e);
		a.ChannelError(this, e);
	}
}
